package com.aki.ai_property.service.impl;

import com.aki.ai_property.dao.AdviseHouseholderDtoDao;
import com.aki.ai_property.dto.AdviseHouseholderDto;
import com.aki.ai_property.service.intf.AdviseHouseholderDtoService;
import com.aki.ai_property.util.StringUtil;
import com.aki.ai_property.vo.PageBean;
import com.aki.ai_property.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ━━━━━━永无BUG!━━━━━━
 *
 * @author AKI
 * @date 2022/8/30
 */
@Service
public class AdviseHouseholderDtoServiceImpl implements AdviseHouseholderDtoService {
    @Autowired
    private AdviseHouseholderDtoDao dao;


    @Override
    public Result save(AdviseHouseholderDto adviseHouseholderDto) {

        if(dao.save(adviseHouseholderDto)>0){
            return Result.ok();
        }
        return Result.fail();
    }

    @Override
    public Result delete(Integer id) {
        if(dao.delete(id)>0){
            return Result.ok();
        }
        return Result.fail();
    }

    @Override
    public Result update(AdviseHouseholderDto adviseHouseholderDto) {
        if(dao.update(adviseHouseholderDto)>0){
            return Result.ok();
        }
        return Result.fail();
    }

    /** 查询 */
    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if (StringUtil.isNotEmpty(name)){
            name="%"+"name"+"%";
        }
        int start = (page-1)*limit;
        return PageBean.ok(dao.selectCount(name), dao.selectPage(name, start, limit));
    }
}
